<!DOCTYPE html>
<html lang="en">
  <head>
    <title>ThemeKit  Reference</title>
    <link rel="stylesheet" type="text/css" href="css/jazzy.css" />
    <link rel="stylesheet" type="text/css" href="css/highlight.css" />
    <meta charset='utf-8'>
    <script src="js/jquery.min.js" defer></script>
    <script src="js/jazzy.js" defer></script>
    
    <script src="js/lunr.min.js" defer></script>
    <script src="js/typeahead.jquery.js" defer></script>
    <script src="js/jazzy.search.js" defer></script>
  </head>
  <body>
    <a title="ThemeKit  Reference"></a>
    <header>
      <div class="content-wrapper">
        <p><a href="index.html">ThemeKit 1.4.0 Docs</a></p>
        <p class="header-right"><a href="https://github.com/luckymarmot/ThemeKit"><img src="img/gh.png"/>View on GitHub</a></p>
        <p class="header-right"><a href="dash-feed://http%3A%2F%2Fthemekit.nunogrilo.com%2Fdocsets%2FThemeKit.xml"><img src="img/dash.png"/>Install in Dash</a></p>
        <p class="header-right">
          <form role="search" action="search.json">
            <input type="text" placeholder="Search documentation" data-typeahead>
          </form>
        </p>
      </div>
    </header>
    <div class="content-wrapper">
      <p id="breadcrumbs">
        <a href="index.html">ThemeKit Reference</a>
        <img id="carat" src="img/carat.png" />
        ThemeKit  Reference
      </p>
    </div>
    <div class="content-wrapper">
      <nav class="sidebar">
        <ul class="nav-groups">
          <li class="nav-group-name">
            <a href="ThemeKit.html">ThemeKit</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Classes/ThemeManager.html">ThemeManager</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/ThemeManager/WindowThemePolicy.html">– WindowThemePolicy</a>
              </li>
              <li class="nav-group-task">
                <a href="Extensions/Notification.html">Notification</a>
              </li>
              <li class="nav-group-task">
                <a href="Extensions/Notification/Name.html">– Name</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="Themes.html">Themes</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Protocols/Theme.html">Theme</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/LightTheme.html">LightTheme</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/DarkTheme.html">DarkTheme</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/SystemTheme.html">SystemTheme</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/UserTheme.html">UserTheme</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="Theme%20Assets.html">Theme Assets</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Classes/ThemeColor.html">ThemeColor</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/ThemeGradient.html">ThemeGradient</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/ThemeImage.html">ThemeImage</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="Extensions.html">Extensions</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Extensions/NSWindow.html">NSWindow</a>
              </li>
              <li class="nav-group-task">
                <a href="Extensions/NSColor.html">NSColor</a>
              </li>
            </ul>
          </li>
        </ul>
      </nav>
      <article class="main-content">
        <section>
          <section class="section">
            
            <p align="left" style="margin-top: 20px;">
  <img src="https://github.com/luckymarmot/ThemeKit/raw/master/Imgs/ThemeKit@2x.png" width="377" height="105" alt="ThemeKit" />
</p>

<p><img src="https://img.shields.io/badge/os-macOS%2010.10%2B-green.svg?style=flat" alt="macOS">
<img src="https://img.shields.io/badge/swift-5.4.1-green.svg?style=flat" alt="Swift4">
<img src="https://img.shields.io/badge/release-1.4.0-blue.svg?style=flat" alt="Release">
<img src="https://img.shields.io/badge/license-MIT-lightgray.svg" alt="MIT">
<img src="https://img.shields.io/badge/dep-CocoaPods-orange.svg" alt="CocoaPods">
<img src="https://img.shields.io/badge/dep-Carthage-orange.svg" alt="Carthage"></p>
<h2 id='summary' class='heading'>Summary</h2>

<p><em>ThemeKit</em> is a lightweight theming library completely written in Swift that provides theming capabilities to both Swift and Objective-C macOS applications.</p>

<p><em>ThemeKit</em> is brought to you with ❤️ by <a href="http://nunogrilo.com">Nuno Grilo</a> and the <a href="https://paw.cloud">Paw</a> <a href="https://github.com/orgs/luckymarmot/people">team</a>.</p>

<p align="left">
  <img src="https://github.com/luckymarmot/ThemeKit/raw/master/Imgs/ThemeKit.gif" width="675" height="378" alt="ThemeKit Animated Demo" />
</p>
<h3 id='quickstart' class='heading'>QuickStart</h3>

<ul>
<li>Download the <a href="https://github.com/luckymarmot/ThemeKit/raw/master/Demo/Bin/Demo.zip">ThemeKit Demo</a> binary and give it a try!</li>
<li>Read the <a href="https://medium.com/@nfgrilo/make-your-macos-app-themable-30dbfe4f5ef0">Make your macOS app themable</a> article (simple tutorial).</li>
<li>Check the <a href="http://themekit.nunogrilo.com">ThemeKit Docs</a>.</li>
</ul>
<h2 id='table-of-contents' class='heading'>Table of Contents</h2>

<ul>
<li><a href="#summary">Summary</a></li>
<li><a href="#features">Features</a></li>
<li><a href="#installation">Installation</a></li>
<li><a href="#usage">Usage</a>

<ul>
<li><a href="#simple-usage">Simple Usage</a></li>
<li><a href="#advanced-usage">Advanced Usage</a>

<ul>
<li><a href="#observing-theme-changes">Observing theme changes</a></li>
<li><a href="#manually-theming-windows">Manually theming windows</a></li>
<li><a href="#nswindow-extension">NSWindow extension</a></li>
</ul></li>
</ul></li>
<li><a href="#theme-aware-assets">Theme-aware Assets</a></li>
<li><a href="#creating-themes">Creating Themes</a>

<ul>
<li><a href="#native-themes">Native Themes</a></li>
<li><a href="#user-themes">User Themes</a></li>
</ul></li>
<li><a href="#faq">FAQ</a></li>
<li><a href="#license">License</a></li>
</ul>
<h2 id='features' class='heading'>Features</h2>

<ul>
<li>Written in Swift 4.2</li>
<li>Optional configuration, none required</li>
<li>Neglected performance impact</li>
<li>Automatically theme windows (configurable)</li>
<li>Themes:

<ul>
<li><a href="http://themekit.nunogrilo.com/Classes/LightTheme.html"><code><a href="Classes/LightTheme.html">LightTheme</a></code></a> (default macOS appearance)</li>
<li><a href="http://themekit.nunogrilo.com/Classes/DarkTheme.html"><code><a href="Classes/DarkTheme.html">DarkTheme</a></code></a></li>
<li><a href="http://themekit.nunogrilo.com/Classes/SystemTheme.html"><code><a href="Classes/SystemTheme.html">SystemTheme</a></code></a> (default theme). Dynamically resolves to <code><a href="Classes/ThemeManager.html#/c:@M@ThemeKit@objc(cs)TKThemeManager(cpy)lightTheme">ThemeManager.lightTheme</a></code> or <code><a href="Classes/ThemeManager.html#/c:@M@ThemeKit@objc(cs)TKThemeManager(cpy)darkTheme">ThemeManager.darkTheme</a></code>, depending on the <em>&ldquo;System Preferences &gt; General &gt; Appearance&rdquo;</em>.</li>
<li>Support for custom themes (<a href="http://themekit.nunogrilo.com/Protocols/Theme.html"><code><a href="Protocols/Theme.html">Theme</a></code></a>)</li>
<li>Support for user-defined themes (<a href="http://themekit.nunogrilo.com/Classes/UserTheme.html"><code><a href="Classes/UserTheme.html">UserTheme</a></code></a>)</li>
</ul></li>
<li>Theme-aware assets:

<ul>
<li><a href="http://themekit.nunogrilo.com/Classes/ThemeColor.html"><code><a href="Classes/ThemeColor.html">ThemeColor</a></code></a>: colors that dynamically change with the theme</li>
<li><a href="http://themekit.nunogrilo.com/Classes/ThemeGradient.html"><code><a href="Classes/ThemeGradient.html">ThemeGradient</a></code></a>: gradients that dynamically change with the theme</li>
<li><a href="http://themekit.nunogrilo.com/Classes/ThemeImage.html"><code><a href="Classes/ThemeImage.html">ThemeImage</a></code></a>: images that dynamically change with the theme</li>
<li>Optional override of <code>NSColor</code> named colors (e.g., <code>labelColor</code>) to dynamically change with the theme</li>
</ul></li>
</ul>
<h2 id='installation' class='heading'>Installation</h2>

<table><thead>
<tr>
<th>ThemeKit Version</th>
<th>Swift Version</th>
</tr>
</thead><tbody>
<tr>
<td>1.0.0</td>
<td>3.0</td>
</tr>
<tr>
<td>1.1.0</td>
<td>4.0</td>
</tr>
<tr>
<td>1.2.0</td>
<td>4.1</td>
</tr>
<tr>
<td>1.2.3</td>
<td>4.2</td>
</tr>
</tbody></table>

<p>There are multiple options to include <em>ThemeKit</em> on your project:</p>

<ul>
<li><strong><a href="https://cocoapods.org">CocoaPods</a></strong></li>
</ul>

<p>Add to your <code>Podfile</code>:</p>
<pre class="highlight plaintext"><code>  use_frameworks!
  target '[YOUR APP TARGET]' do
      pod 'macOSThemeKit', '~&gt; 1.2.0'
  end
</code></pre>

<p>When using CocoaPods, the ThemeKit module is named <code>macOSThemeKit</code>:</p>
<pre class="highlight plaintext"><code>  import macOSThemeKit
</code></pre>

<ul>
<li><strong><a href="https://github.com/Carthage/Carthage">Carthage</a></strong></li>
</ul>
<pre class="highlight plaintext"><code>  github "luckymarmot/ThemeKit"
</code></pre>

<p>Then import ThemeKit module with:</p>
<pre class="highlight plaintext"><code>  import ThemeKit
</code></pre>

<ul>
<li><strong>Manually</strong>

<ul>
<li>Either add <code>ThemeKit.framework</code> on your project, <strong>or</strong>, manually add source files from the <code>ThemeKit\</code> folder to your project</li>
<li>If importing into a Objective-C project, you will need to include all the Swift related frameworks as well (as reported <a href="https://github.com/luckymarmot/ThemeKit/issues/6">here</a>)</li>
</ul></li>
</ul>

<p>Then import ThemeKit module with:</p>
<pre class="highlight plaintext"><code>  import ThemeKit
</code></pre>
<h2 id='usage' class='heading'>Usage</h2>
<h3 id='simple-usage' class='heading'>Simple Usage</h3>

<p>At its simpler usage, applications can be themed with a single line command:</p>
<h5 id='in-swift' class='heading'>In Swift:</h5>
<pre class="highlight swift"><code><span class="kd">func</span> <span class="nf">applicationWillFinishLaunching</span><span class="p">(</span><span class="n">_</span> <span class="nv">notification</span><span class="p">:</span> <span class="kt">Notification</span><span class="p">)</span> <span class="p">{</span>

    <span class="c1">/// Apply the dark theme</span>
    <span class="kt">ThemeManager</span><span class="o">.</span><span class="n">darkTheme</span><span class="o">.</span><span class="nf">apply</span><span class="p">()</span>

    <span class="c1">/// or, the light theme</span>
    <span class="c1">//ThemeManager.lightTheme.apply()</span>

    <span class="c1">/// or, the 'system' theme, which dynamically changes to light or dark, </span>
    <span class="c1">/// respecting *System Preferences &gt; General &gt; Appearance* setting.</span>
    <span class="c1">//ThemeManager.systemTheme.apply()</span>

<span class="p">}</span>
</code></pre>
<h5 id='in-objective-c' class='heading'>In Objective-C:</h5>
<pre class="highlight objective_c"><code><span class="k">-</span> <span class="p">(</span><span class="kt">void</span><span class="p">)</span><span class="nf">applicationWillFinishLaunching</span><span class="p">:(</span><span class="n">NSNotification</span> <span class="o">*</span><span class="p">)</span><span class="nv">aNotification</span> <span class="p">{</span>

    <span class="c1">// Apply the dark theme</span>
    <span class="n">TKDarkTheme</span> <span class="o">*</span><span class="n">darkTheme</span> <span class="o">=</span> <span class="n">TKThemeManager</span><span class="p">.</span><span class="n">darkTheme</span><span class="p">;</span>
    <span class="p">[[</span><span class="n">TKThemeManager</span> <span class="nf">sharedManager</span><span class="p">]</span> <span class="nf">setTheme</span><span class="p">:</span><span class="n">darkTheme</span><span class="p">];</span>

<span class="p">}</span>
</code></pre>
<h3 id='advanced-usage' class='heading'>Advanced Usage</h3>

<p>The following code will define which windows should be automatically themed (<a href="http://themekit.nunogrilo.com/Classes/ThemeManager/WindowThemePolicy.html"><code>WindowThemePolicy</code></a>) and add support for user themes (<a href="http://themekit.nunogrilo.com/Classes/UserTheme.html"><code><a href="Classes/UserTheme.html">UserTheme</a></code></a>):</p>
<h5 id='in-swift' class='heading'>In Swift:</h5>
<pre class="highlight swift"><code><span class="kd">func</span> <span class="nf">applicationWillFinishLaunching</span><span class="p">(</span><span class="n">_</span> <span class="nv">notification</span><span class="p">:</span> <span class="kt">Notification</span><span class="p">)</span> <span class="p">{</span>

    <span class="c1">/// Define default theme.</span>
    <span class="c1">/// Used on first run. Default: `SystemTheme`.</span>
    <span class="c1">/// Note: `SystemTheme` is a special theme that resolves to `ThemeManager.lightTheme` or `ThemeManager.darkTheme`,</span>
    <span class="c1">/// depending on the macOS preference at 'System Preferences &gt; General &gt; Appearance'.</span>
    <span class="kt">ThemeManager</span><span class="o">.</span><span class="n">defaultTheme</span> <span class="o">=</span> <span class="kt">ThemeManager</span><span class="o">.</span><span class="n">lightTheme</span>

    <span class="c1">/// Define window theme policy.</span>
    <span class="kt">ThemeManager</span><span class="o">.</span><span class="n">shared</span><span class="o">.</span><span class="n">windowThemePolicy</span> <span class="o">=</span> <span class="o">.</span><span class="n">themeAllWindows</span>
    <span class="c1">//ThemeManager.shared.windowThemePolicy = .themeSomeWindows(windowClasses: [MyWindow.self])</span>
    <span class="c1">//ThemeManager.shared.windowThemePolicy = .doNotThemeSomeWindows(windowClasses: [NSPanel.self])</span>
    <span class="c1">//ThemeManager.shared.windowThemePolicy = .doNotThemeWindows</span>

    <span class="c1">/// Enable &amp; configure user themes.</span>
    <span class="c1">/// Will use folder `(...)/Application Support/{your_app_bundle_id}/Themes`.</span>
    <span class="k">let</span> <span class="nv">applicationSupportURLs</span> <span class="o">=</span> <span class="kt">NSSearchPathForDirectoriesInDomains</span><span class="p">(</span><span class="o">.</span><span class="n">applicationSupportDirectory</span><span class="p">,</span> <span class="o">.</span><span class="n">userDomainMask</span><span class="p">,</span> <span class="kc">true</span><span class="p">)</span>
    <span class="k">let</span> <span class="nv">thisAppSupportURL</span> <span class="o">=</span> <span class="kt">URL</span><span class="o">.</span><span class="nf">init</span><span class="p">(</span><span class="nv">fileURLWithPath</span><span class="p">:</span> <span class="n">applicationSupportURLs</span><span class="o">.</span><span class="n">first</span><span class="o">!</span><span class="p">)</span><span class="o">.</span><span class="nf">appendingPathComponent</span><span class="p">(</span><span class="kt">Bundle</span><span class="o">.</span><span class="n">main</span><span class="o">.</span><span class="n">bundleIdentifier</span><span class="o">!</span><span class="p">)</span>
    <span class="k">let</span> <span class="nv">userThemesFolderURL</span> <span class="o">=</span> <span class="n">thisAppSupportURL</span><span class="o">.</span><span class="nf">appendingPathComponent</span><span class="p">(</span><span class="s">"Themes"</span><span class="p">)</span>
    <span class="kt">ThemeManager</span><span class="o">.</span><span class="n">shared</span><span class="o">.</span><span class="n">userThemesFolderURL</span> <span class="o">=</span> <span class="n">userThemesFolderURL</span>

    <span class="c1">/// Change the default light and dark theme, used when `SystemTheme` is selected.</span>
    <span class="c1">//ThemeManager.lightTheme = ThemeManager.shared.theme(withIdentifier: PaperTheme.identifier)!</span>
    <span class="c1">//ThemeManager.darkTheme = ThemeManager.shared.theme(withIdentifier: "com.luckymarmot.ThemeKit.PurpleGreen")!</span>

    <span class="c1">/// Apply last applied theme (or the default theme, if no previous one)</span>
    <span class="kt">ThemeManager</span><span class="o">.</span><span class="n">shared</span><span class="o">.</span><span class="nf">applyLastOrDefaultTheme</span><span class="p">()</span>

<span class="p">}</span>    
</code></pre>
<h5 id='in-objective-c' class='heading'>In Objective-C:</h5>
<pre class="highlight objective_c"><code><span class="k">-</span> <span class="p">(</span><span class="kt">void</span><span class="p">)</span><span class="nf">applicationWillFinishLaunching</span><span class="p">:(</span><span class="n">NSNotification</span> <span class="o">*</span><span class="p">)</span><span class="nv">aNotification</span> <span class="p">{</span>

    <span class="c1">/// Define default theme.</span>
    <span class="c1">/// Used on first run. Default: `SystemTheme`.</span>
    <span class="c1">/// Note: `SystemTheme` is a special theme that resolves to `ThemeManager.lightTheme` or `ThemeManager.darkTheme`,</span>
    <span class="c1">/// depending on the macOS preference at 'System Preferences &gt; General &gt; Appearance'.</span>
    <span class="p">[</span><span class="n">TKThemeManager</span> <span class="nf">setDefaultTheme</span><span class="p">:</span><span class="n">TKThemeManager</span><span class="p">.</span><span class="n">lightTheme</span><span class="p">];</span>

    <span class="c1">/// Define window theme policy.</span>
    <span class="p">[</span><span class="n">TKThemeManager</span> <span class="nf">sharedManager</span><span class="p">].</span><span class="n">windowThemePolicy</span> <span class="o">=</span> <span class="n">TKThemeManagerWindowThemePolicyThemeAllWindows</span><span class="p">;</span>
    <span class="c1">//[TKThemeManager sharedManager].windowThemePolicy = TKThemeManagerWindowThemePolicyThemeSomeWindows;</span>
    <span class="c1">//[TKThemeManager sharedManager].themableWindowClasses = @[[MyWindow class]];</span>
    <span class="c1">//[TKThemeManager sharedManager].windowThemePolicy = TKThemeManagerWindowThemePolicyDoNotThemeSomeWindows;</span>
    <span class="c1">//[TKThemeManager sharedManager].notThemableWindowClasses = @[[NSPanel class]];</span>
    <span class="c1">//[TKThemeManager sharedManager].windowThemePolicy = TKThemeManagerWindowThemePolicyDoNotThemeWindows;</span>

    <span class="c1">/// Enable &amp; configure user themes.</span>
    <span class="c1">/// Will use folder `(...)/Application Support/{your_app_bundle_id}/Themes`.</span>
    <span class="n">NSArray</span><span class="o">&lt;</span><span class="n">NSString</span><span class="o">*&gt;*</span> <span class="n">applicationSupportURLs</span> <span class="o">=</span> <span class="n">NSSearchPathForDirectoriesInDomains</span><span class="p">(</span><span class="n">NSApplicationSupportDirectory</span><span class="p">,</span> <span class="n">NSUserDomainMask</span><span class="p">,</span> <span class="nb">YES</span><span class="p">);</span>
    <span class="n">NSURL</span><span class="o">*</span> <span class="n">thisAppSupportURL</span> <span class="o">=</span> <span class="p">[[</span><span class="n">NSURL</span> <span class="nf">fileURLWithPath</span><span class="p">:</span><span class="n">applicationSupportURLs</span><span class="p">.</span><span class="n">firstObject</span><span class="p">]</span> <span class="nf">URLByAppendingPathComponent</span><span class="p">:[</span><span class="n">NSBundle</span> <span class="nf">mainBundle</span><span class="p">].</span><span class="n">bundleIdentifier</span><span class="p">];</span>
    <span class="n">NSURL</span><span class="o">*</span> <span class="n">userThemesFolderURL</span> <span class="o">=</span> <span class="p">[</span><span class="n">thisAppSupportURL</span> <span class="nf">URLByAppendingPathComponent</span><span class="p">:</span><span class="s">@"Themes"</span><span class="p">];</span>
    <span class="p">[</span><span class="n">TKThemeManager</span> <span class="nf">sharedManager</span><span class="p">].</span><span class="n">userThemesFolderURL</span> <span class="o">=</span> <span class="n">userThemesFolderURL</span><span class="p">;</span>

    <span class="c1">/// Change the default light and dark theme, used when `SystemTheme` is selected.</span>
    <span class="c1">//TKThemeManager.lightTheme = [[TKThemeManager sharedManager] themeWithIdentifier:PaperTheme.identifier];</span>
    <span class="c1">//TKThemeManager.darkTheme = [[TKThemeManager sharedManager] themeWithIdentifier:@"com.luckymarmot.ThemeKit.PurpleGreen"];</span>

    <span class="c1">/// Apply last applied theme (or the default theme, if no previous one)</span>
    <span class="p">[[</span><span class="n">TKThemeManager</span> <span class="nf">sharedManager</span><span class="p">]</span> <span class="nf">applyLastOrDefaultTheme</span><span class="p">];</span>

<span class="p">}</span>
</code></pre>

<p>Please check the <strong>Demo</strong> application source code for a more complete usage example of <em>ThemeKit</em>.</p>
<h4 id='observing-theme-changes' class='heading'>Observing theme changes</h4>

<p>ThemeKit provides the following notifications:</p>

<ul>
<li><code><a href="Extensions/Notification/Name.html#/s:So18NSNotificationNamea8ThemeKitE010willChangeC0ABvpZ">Notification.Name.willChangeTheme</a></code> is sent when current theme is about to change</li>
<li><code><a href="Extensions/Notification/Name.html#/s:So18NSNotificationNamea8ThemeKitE09didChangeC0ABvpZ">Notification.Name.didChangeTheme</a></code> is sent when current theme did change</li>
<li><code><a href="Extensions/Notification/Name.html#/s:So18NSNotificationNamea8ThemeKitE015didChangeSystemC0ABvpZ">Notification.Name.didChangeSystemTheme</a></code> is sent when system theme did change (System Preference &gt; General)</li>
</ul>

<p>Example:</p>
<pre class="highlight swift"><code><span class="c1">// Register to be notified of theme changes</span>
<span class="kt">NotificationCenter</span><span class="o">.</span><span class="k">default</span><span class="o">.</span><span class="nf">addObserver</span><span class="p">(</span><span class="k">self</span><span class="p">,</span> <span class="nv">selector</span><span class="p">:</span> <span class="kd">#selector(</span><span class="nf">changedTheme(_:)</span><span class="kd">)</span><span class="p">,</span> <span class="nv">name</span><span class="p">:</span> <span class="o">.</span><span class="n">didChangeTheme</span><span class="p">,</span> <span class="nv">object</span><span class="p">:</span> <span class="kc">nil</span><span class="p">)</span>

<span class="kd">@objc</span> <span class="kd">private</span> <span class="kd">func</span> <span class="nf">changedTheme</span><span class="p">(</span><span class="n">_</span> <span class="nv">notification</span><span class="p">:</span> <span class="kt">Notification</span><span class="p">)</span> <span class="p">{</span>
    <span class="c1">// ...</span>
<span class="p">}</span>
</code></pre>

<p>Additionally, the following properties are KVO compliant:</p>

<ul>
<li><a href="http://themekit.nunogrilo.com/Classes/ThemeManager.html#/s:vC8ThemeKit12ThemeManager5themePS_5Theme_"><code>ThemeManager.shared.theme</code></a></li>
<li><a href="http://themekit.nunogrilo.com/Classes/ThemeManager.html#/s:vC8ThemeKit12ThemeManager14effectiveThemePS_5Theme_"><code>ThemeManager.shared.effectiveTheme</code></a></li>
<li><a href="http://themekit.nunogrilo.com/Classes/ThemeManager.html#/s:vC8ThemeKit12ThemeManager6themesGSaPS_5Theme__"><code>ThemeManager.shared.themes</code></a></li>
<li><a href="http://themekit.nunogrilo.com/Classes/ThemeManager.html#/s:vC8ThemeKit12ThemeManager10userThemesGSaPS_5Theme__"><code>ThemeManager.shared.userThemes</code></a></li>
</ul>

<p>Example:</p>
<pre class="highlight swift"><code><span class="c1">// Register for KVO changes on ThemeManager.shared.effectiveTheme</span>
<span class="kt">ThemeManager</span><span class="o">.</span><span class="n">shared</span><span class="o">.</span><span class="nf">addObserver</span><span class="p">(</span><span class="k">self</span><span class="p">,</span> <span class="nv">forKeyPath</span><span class="p">:</span> <span class="s">"effectiveTheme"</span><span class="p">,</span> <span class="nv">options</span><span class="p">:</span> <span class="kt">NSKeyValueObservingOptions</span><span class="o">.</span><span class="nf">init</span><span class="p">(</span><span class="nv">rawValue</span><span class="p">:</span> <span class="mi">0</span><span class="p">),</span> <span class="nv">context</span><span class="p">:</span> <span class="kc">nil</span><span class="p">)</span>

<span class="kd">public</span> <span class="k">override</span> <span class="kd">func</span> <span class="nf">observeValue</span><span class="p">(</span><span class="n">forKeyPath</span> <span class="nv">keyPath</span><span class="p">:</span> <span class="kt">String</span><span class="p">?,</span> <span class="n">of</span> <span class="nv">object</span><span class="p">:</span> <span class="kt">Any</span><span class="p">?,</span> <span class="nv">change</span><span class="p">:</span> <span class="p">[</span><span class="kt">NSKeyValueChangeKey</span> <span class="p">:</span> <span class="kt">Any</span><span class="p">]?,</span> <span class="nv">context</span><span class="p">:</span> <span class="kt">UnsafeMutableRawPointer</span><span class="p">?)</span> <span class="p">{</span>
    <span class="k">if</span> <span class="n">keyPath</span> <span class="o">==</span> <span class="s">"effectiveTheme"</span> <span class="p">{</span>
        <span class="c1">// ...</span>
   <span class="p">}</span>
<span class="p">}</span>
</code></pre>
<h4 id='manually-theming-windows' class='heading'>Manually theming windows</h4>

<p>In case (<a href="http://themekit.nunogrilo.com/Classes/ThemeManager/WindowThemePolicy.html"><code>WindowThemePolicy</code></a>) was NOT set to <code>.themeAllWindows</code>, you may need to manually theme a window. You can use our <code>NSWindow</code> extension for that:</p>
<h5 id='a-href-http-themekit-nunogrilo-com-extensions-nswindow-html-nswindow-extension-a' class='heading'><a href="http://themekit.nunogrilo.com/Extensions/NSWindow.html">NSWindow Extension</a></h5>

<ul>
<li><p><a href="http://themekit.nunogrilo.com/Extensions/NSWindow.html#/s:FE8ThemeKitCSo8NSWindow5themeFT_T_"><code><a href="Extensions/NSWindow.html#/c:@CM@ThemeKit@@objc(cs)NSWindow(im)theme">NSWindow.theme()</a></code></a></p>

<p>Theme window if appearance needs update. Doesn&rsquo;t check for policy compliance.</p></li>
<li><p><a href="http://themekit.nunogrilo.com/Extensions/NSWindow.html#/s:FE8ThemeKitCSo8NSWindow37themeIfCompliantWithWindowThemePolicyFT_T_"><code><a href="Extensions/NSWindow.html#/c:@CM@ThemeKit@@objc(cs)NSWindow(im)themeIfCompliantWithWindowThemePolicy">NSWindow.themeIfCompliantWithWindowThemePolicy()</a></code></a></p>

<p>Theme window if compliant to <code>ThemeManager.shared.windowThemePolicy</code> (and if appearance needs update).</p></li>
<li><p><a href="http://themekit.nunogrilo.com/Extensions/NSWindow.html#/s:ZFE8ThemeKitCSo8NSWindow15themeAllWindowsFT_T_"><code><a href="Extensions/NSWindow.html#/c:@CM@ThemeKit@@objc(cs)NSWindow(cm)themeAllWindows">NSWindow.themeAllWindows()</a></code></a></p>

<p>Theme all windows compliant to <code>ThemeManager.shared.windowThemePolicy</code> (and if appearance needs update).</p></li>
<li><p><a href="http://themekit.nunogrilo.com/Extensions/NSWindow.html#/s:vE8ThemeKitCSo8NSWindow11windowThemeGSqPS_5Theme__"><code><a href="Extensions/NSWindow.html#/c:@CM@ThemeKit@@objc(cs)NSWindow(py)windowTheme">NSWindow.windowTheme</a></code></a></p>

<p>Any window specific theme.
This is, usually, <code>nil</code>, which means the current global theme will be used.
Please note that when using window specific themes, only the associated <code>NSAppearance</code> will be automatically set. All theme aware assets (<code><a href="Classes/ThemeColor.html">ThemeColor</a></code>, <code><a href="Classes/ThemeGradient.html">ThemeGradient</a></code> and <code><a href="Classes/ThemeImage.html">ThemeImage</a></code>) should call methods that returns a resolved color instead (which means they don&rsquo;t change with the theme change, you need to observe theme changes manually, and set colors afterwards):</p>

<ul>
<li><code>ThemeColor.color(for view:, selector:)</code></li>
<li><code>ThemeGradient.gradient(for view:, selector:)</code></li>
<li><code>ThemeImage.image(for view:, selector:)</code></li>
</ul>

<p>Additionally, please note that system overridden colors (<code>NSColor.*</code>) will always use the global theme.</p></li>
<li><p><a href="http://themekit.nunogrilo.com/Extensions/NSWindow.html#/s:vE8ThemeKitCSo8NSWindow20windowEffectiveThemePS_5Theme_"><code><a href="Extensions/NSWindow.html#/c:@CM@ThemeKit@@objc(cs)NSWindow(py)windowEffectiveTheme">NSWindow.windowEffectiveTheme</a></code></a></p>

<p>Returns the current effective theme (read-only).</p></li>
<li><p><a href="http://themekit.nunogrilo.com/Extensions/NSWindow.html#/s:vE8ThemeKitCSo8NSWindow30windowEffectiveThemeAppearanceGSqCSo12NSAppearance_"><code><a href="Extensions/NSWindow.html#/c:@CM@ThemeKit@@objc(cs)NSWindow(py)windowEffectiveThemeAppearance">NSWindow.windowEffectiveThemeAppearance</a></code></a></p>

<p>Returns the current effective appearance (read-only).</p></li>
</ul>
<h2 id='theme-aware-assets' class='heading'>Theme-aware Assets</h2>

<p><a href="http://themekit.nunogrilo.com/Classes/ThemeColor.html"><code><a href="Classes/ThemeColor.html">ThemeColor</a></code></a>, <a href="http://themekit.nunogrilo.com/Classes/ThemeGradient.html"><code><a href="Classes/ThemeGradient.html">ThemeGradient</a></code></a> and <a href="http://themekit.nunogrilo.com/Classes/ThemeImage.html"><code><a href="Classes/ThemeImage.html">ThemeImage</a></code></a> provides colors, gradients and images, respectively, that dynamically change with the current theme.</p>

<p>Additionally, named colors from the <code>NSColor</code> class defined on the <code><a href="Classes/ThemeColor.html">ThemeColor</a></code> subclass extension will override the system ones, providing theme-aware colors.</p>

<p>For example, a project defines a <code>ThemeColor.brandColor</code> color. This will resolve to different colors at runtime, depending on the selected theme:</p>

<ul>
<li><code>ThemeColor.brandColor</code> will resolve to <code>NSColor.blue</code> if the light theme is selected</li>
<li><code>ThemeColor.brandColor</code> will resolve to <code>NSColor.white</code> if the dark theme is selected</li>
<li><code>ThemeColor.brandColor</code> will resolve to <code>rgba(100, 50, 0, 0.5)</code> for some user-defined theme (<a href="http://themekit.nunogrilo.com/Classes/UserTheme.html"><code><a href="Classes/UserTheme.html">UserTheme</a></code></a>)</li>
</ul>

<p>Similarly, defining a <code>ThemeColor.labelColor</code> will override <code>NSColor.labelColor</code> (<code><a href="Classes/ThemeColor.html">ThemeColor</a></code> is a subclass of <code>NSColor</code>), and <em>ThemeKit</em> will allow <code>labelColor</code> to be customized on a per-theme basis as well. </p>

<p>The <a href="http://themekit.nunogrilo.com/Extensions/NSColor.html">NSColor Extension</a> may be useful when overriding colors in ThemeColor extensions.</p>
<h3 id='fallback-assets' class='heading'>Fallback Assets</h3>

<p>ThemeKit provides a simple fallback mechanism when looking up assets in the current theme. It will search for assets, in order:</p>

<ul>
<li>the asset name, defined in theme (e.g., <code>myBackgroundColor</code>)</li>
<li><code>fallbackForegroundColor</code>, <code>fallbackBackgroundColor</code>, <code>fallbackGradient</code> or <code>fallbackImage</code> defined in theme, depending if asset is a foreground/background color, gradient or image, respectively</li>
<li><code>defaultFallbackForegroundColor</code>, <code>defaultFallbackBackgroundColor</code>, <code>fallbackGradient</code> or <code>defaultFallbackImage</code> defined internally, depending if asset is a foreground/background color, gradient or image, respectively</li>
</ul>

<p>However, for overridden system named colors, the fallback mechanism is different and simpler:</p>

<ul>
<li>the asset name, defined in theme (e.g., <code>labelColor</code>)</li>
<li>original asset defined in the system (e.g., <code>NSColor.labelColor</code>)</li>
</ul>

<p>Please refer to <a href="http://themekit.nunogrilo.com/Classes/ThemeColor.html"><code><a href="Classes/ThemeColor.html">ThemeColor</a></code></a>, <a href="http://themekit.nunogrilo.com/Classes/ThemeGradient.html"><code><a href="Classes/ThemeGradient.html">ThemeGradient</a></code></a> and <a href="http://themekit.nunogrilo.com/Classes/ThemeImage.html"><code><a href="Classes/ThemeImage.html">ThemeImage</a></code></a> for more information.</p>
<h2 id='creating-themes' class='heading'>Creating Themes</h2>
<h3 id='native-themes' class='heading'>Native Themes</h3>

<p>For creating additional themes, you only need to create a class that conforms to the <a href="http://themekit.nunogrilo.com/Protocols/Theme.html"><code><a href="Protocols/Theme.html">Theme</a></code></a> protocol and extends <code>NSObject</code>.</p>

<p>Sample theme:</p>
<pre class="highlight swift"><code><span class="kd">import</span> <span class="kt">Cocoa</span>
<span class="kd">import</span> <span class="kt">ThemeKit</span>

<span class="kd">class</span> <span class="kt">MyOwnTheme</span><span class="p">:</span> <span class="kt">NSObject</span><span class="p">,</span> <span class="kt">Theme</span> <span class="p">{</span>

    <span class="c1">/// Light theme identifier (static).</span>
    <span class="kd">public</span> <span class="kd">static</span> <span class="k">var</span> <span class="nv">identifier</span><span class="p">:</span> <span class="kt">String</span> <span class="o">=</span> <span class="s">"com.luckymarmot.ThemeKit.MyOwnTheme"</span>

    <span class="c1">/// Unique theme identifier.</span>
    <span class="kd">public</span> <span class="k">var</span> <span class="nv">identifier</span><span class="p">:</span> <span class="kt">String</span> <span class="o">=</span> <span class="kt">MyOwnTheme</span><span class="o">.</span><span class="n">identifier</span>

    <span class="c1">/// Theme display name.</span>
    <span class="kd">public</span> <span class="k">var</span> <span class="nv">displayName</span><span class="p">:</span> <span class="kt">String</span> <span class="o">=</span> <span class="s">"My Own Theme"</span>

    <span class="c1">/// Theme short display name.</span>
    <span class="kd">public</span> <span class="k">var</span> <span class="nv">shortDisplayName</span><span class="p">:</span> <span class="kt">String</span> <span class="o">=</span> <span class="s">"My Own"</span>

    <span class="c1">/// Is this a dark theme?</span>
    <span class="kd">public</span> <span class="k">var</span> <span class="nv">isDarkTheme</span><span class="p">:</span> <span class="kt">Bool</span> <span class="o">=</span> <span class="kc">false</span>

    <span class="c1">/// Description (optional).</span>
    <span class="kd">public</span> <span class="k">override</span> <span class="k">var</span> <span class="nv">description</span> <span class="p">:</span> <span class="kt">String</span> <span class="p">{</span>
        <span class="k">return</span> <span class="s">"&lt;</span><span class="se">\(</span><span class="kt">MyOwnTheme</span><span class="o">.</span><span class="k">self</span><span class="se">)</span><span class="s">: </span><span class="se">\(</span><span class="nf">themeDescription</span><span class="p">(</span><span class="k">self</span><span class="p">)</span><span class="se">)</span><span class="s">&gt;"</span>
    <span class="p">}</span>

    <span class="c1">// MARK: -</span>
    <span class="c1">// MARK: Theme Assets</span>

    <span class="c1">// Here you can define the instance methods for the class methods defined </span>
    <span class="c1">// on `ThemeColor`, `ThemeGradient` and `ThemeImage`, if any. Check</span>
    <span class="c1">// documentation of these classes for more details.</span>
<span class="p">}</span>
</code></pre>
<h3 id='user-themes' class='heading'>User Themes</h3>

<p>ThemeKit also supports definition of additional themes with simple text files (<code>.theme</code> files). Example of a very basic <code>.theme</code> file:</p>
<pre class="highlight ruby"><code><span class="sr">//</span> <span class="o">*************************</span> <span class="no">Theme</span> <span class="no">Info</span> <span class="o">*************************</span> <span class="sr">//</span>
<span class="n">displayName</span> <span class="o">=</span> <span class="no">My</span> <span class="no">Theme</span> <span class="mi">1</span>
<span class="n">identifier</span> <span class="o">=</span> <span class="n">com</span><span class="p">.</span><span class="nf">luckymarmot</span><span class="o">.</span><span class="no">ThemeKit</span><span class="o">.</span><span class="no">MyTheme1</span>
<span class="n">darkTheme</span> <span class="o">=</span> <span class="kp">true</span>

<span class="sr">//</span> <span class="o">*********************</span> <span class="no">Colors</span> <span class="o">&amp;</span> <span class="no">Gradients</span> <span class="o">*********************</span> <span class="sr">//</span>
<span class="c1"># define color for `ThemeColor.brandColor`</span>
<span class="n">brandColor</span> <span class="o">=</span> <span class="vg">$blue</span>
<span class="c1"># define a new color for `NSColor.labelColor` (overriding)</span>
<span class="n">labelColor</span> <span class="o">=</span> <span class="n">rgb</span><span class="p">(</span><span class="mi">11</span><span class="p">,</span> <span class="mi">220</span><span class="p">,</span> <span class="mi">111</span><span class="p">)</span>
<span class="c1"># define gradient for `ThemeGradient.brandGradient`</span>
<span class="n">brandGradient</span> <span class="o">=</span> <span class="n">linear</span><span class="o">-</span><span class="n">gradient</span><span class="p">(</span><span class="vg">$orange</span><span class="p">.</span><span class="nf">sky</span><span class="p">,</span> <span class="n">rgba</span><span class="p">(</span><span class="mi">200</span><span class="p">,</span> <span class="mi">140</span><span class="p">,</span> <span class="mi">60</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">))</span>

<span class="sr">//</span> <span class="o">*********************</span> <span class="no">Images</span> <span class="o">&amp;</span> <span class="no">Patterns</span> <span class="o">**********************</span> <span class="sr">//</span>
<span class="c1"># define pattern image from named image "paper" for color `ThemeColor.contentBackgroundColor`</span>
<span class="n">contentBackgroundColor</span> <span class="o">=</span> <span class="n">pattern</span><span class="p">(</span><span class="n">named</span><span class="ss">:paper</span><span class="p">)</span>
<span class="c1"># define pattern image from filesystem (relative to user themes folder) for color `ThemeColor.bottomBackgroundColor`</span>
<span class="n">bottomBackgroundColor</span> <span class="o">=</span> <span class="n">pattern</span><span class="p">(</span><span class="n">file</span><span class="p">:</span><span class="o">..</span><span class="sr">/some/</span><span class="n">path</span><span class="o">/</span><span class="n">some</span><span class="o">-</span><span class="n">file</span><span class="p">.</span><span class="nf">png</span><span class="p">)</span>
<span class="c1"># define image using named image "apple"</span>
<span class="n">namedImage</span> <span class="o">=</span> <span class="n">image</span><span class="p">(</span><span class="n">named</span><span class="ss">:apple</span><span class="p">)</span>
<span class="c1"># define image using from filesystem (relative to user themes folder)</span>
<span class="n">fileImage</span> <span class="o">=</span> <span class="n">image</span><span class="p">(</span><span class="n">file</span><span class="p">:</span><span class="o">..</span><span class="sr">/some/</span><span class="n">path</span><span class="o">/</span><span class="n">some</span><span class="o">-</span><span class="n">file</span><span class="p">.</span><span class="nf">jpg</span><span class="p">)</span>

<span class="sr">//</span> <span class="o">***********************</span> <span class="no">Common</span> <span class="no">Colors</span> <span class="o">************************</span> <span class="sr">//</span>
<span class="n">blue</span> <span class="o">=</span> <span class="n">rgb</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">170</span><span class="p">,</span> <span class="mi">255</span><span class="p">)</span>
<span class="n">orange</span><span class="p">.</span><span class="nf">sky</span> <span class="o">=</span> <span class="n">rgb</span><span class="p">(</span><span class="mi">160</span><span class="p">,</span> <span class="mi">90</span><span class="p">,</span> <span class="mi">45</span><span class="p">,</span> <span class="o">.</span><span class="mi">5</span><span class="p">)</span>

<span class="sr">//</span> <span class="o">**********************</span> <span class="no">Fallback</span> <span class="no">Assets</span> <span class="o">***********************</span> <span class="sr">//</span>
<span class="n">fallbackForegroundColor</span> <span class="o">=</span> <span class="n">rgb</span><span class="p">(</span><span class="mi">255</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">90</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">)</span>
<span class="n">fallbackBackgroundColor</span> <span class="o">=</span> <span class="n">rgb</span><span class="p">(</span><span class="mi">255</span><span class="p">,</span> <span class="mi">200</span><span class="p">,</span> <span class="mi">190</span><span class="p">)</span>
<span class="n">fallbackGradient</span> <span class="o">=</span> <span class="n">linear</span><span class="o">-</span><span class="n">gradient</span><span class="p">(</span><span class="vg">$blue</span><span class="p">,</span> <span class="n">rgba</span><span class="p">(</span><span class="mi">200</span><span class="p">,</span> <span class="mi">140</span><span class="p">,</span> <span class="mi">60</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">))</span>

</code></pre>

<p>To enable support for user themes, just need to set the location for them:</p>
<pre class="highlight swift"><code><span class="c1">// Setup ThemeKit user themes folder</span>
<span class="kt">ThemeManager</span><span class="o">.</span><span class="n">shared</span><span class="o">.</span><span class="n">userThemesFolderURL</span> <span class="o">=</span> <span class="c1">//...</span>
</code></pre>

<p>Please refer to <a href="http://themekit.nunogrilo.com/Classes/UserTheme.html"><code><a href="Classes/UserTheme.html">UserTheme</a></code></a> for more information.</p>
<h2 id='faq' class='heading'>FAQ</h2>
<h3 id='strong-where-can-i-find-the-api-documentation-strong' class='heading'><strong>Where can I find the API documentation?</strong></h3>

<p>Documentation can be found <a href="http://themekit.nunogrilo.com">here</a>. You can also <a href="dash-feed://http%3A%2F%2Fthemekit%2Enunogrilo%2Ecom%2Fdocsets%2FThemeKit%2Exml">install it</a> on <a href="https://kapeli.com/dash">Dash</a>.</p>
<h3 id='strong-can-the-window-titlebar-toolbar-tabbar-be-themed-strong' class='heading'><strong>Can the window titlebar/toolbar/tabbar be themed?</strong></h3>

<p>Yes - please check one way to do it on the <a href="https://github.com/luckymarmot/ThemeKit/tree/master/Demo">Demo project</a>.
Basically, a <a href="https://github.com/luckymarmot/ThemeKit/blob/master/Demo/Demo/TitleBarOverlayView.swift">TitleBarOverlayView</a> view is added <em>below</em> the window title bar, <a href="https://github.com/luckymarmot/ThemeKit/blob/master/Demo/Demo/WindowController.swift#L45-L82">as shown on the WindowController</a> controller.</p>
<h3 id='strong-can-controls-be-tinted-with-different-colors-strong' class='heading'><strong>Can controls be tinted with different colors?</strong></h3>

<p>Other than the colors set by the inherited appearance - light (dark text on light background) or dark (light text on dark background) - natively, it is not possible to specify different colors for the text and/or background fills of controls (buttons, popups, etc).</p>

<p>For simple cases, overriding <code>NSColor</code> can be sufficient: for example, <code>NSColor.labelColor</code> is a named color used for text labels; overriding it will allow to have all labels themed accordingly. You can get a list of all overridable named colors (class method names) with <code><a href="Extensions/NSColor.html#/c:@CM@ThemeKit@@objc(cs)NSColor(cm)colorMethodNames">NSColor.colorMethodNames()</a></code>.</p>

<p>For more complex cases, like views/controls with custom drawing, please refer to next question.</p>
<h3 id='strong-can-i-make-custom-drawing-views-controls-theme-aware-strong' class='heading'><strong>Can I make custom drawing views/controls theme-aware?</strong></h3>

<p>Yes, you can! Implement your own custom controls drawing using <a href="#theme-aware-assets">Theme-aware Assets</a> (<code><a href="Classes/ThemeColor.html">ThemeColor</a></code> and <code><a href="Classes/ThemeGradient.html">ThemeGradient</a></code>) so that your controls drawing will always adapt to your current theme&hellip; automatically!</p>

<p>In case needed (for example, if drawing is being cached), you can observe when theme changes to refresh the UI or to perform any theme related operation. Check <em>&ldquo;Observing theme changes&rdquo;</em> on <a href="#usage">Usage</a> section above.</p>
<h3 id='strong-nstableview-cells-are-getting-a-background-color-after-being-themed-strong' class='heading'><strong>NSTableView cells are getting a background color after being themed!</strong></h3>

<p>Please check <a href="https://github.com/luckymarmot/ThemeKit/issues/18">this issue</a>. This theming issue only affects view-based <code>NSTableView</code>s, when placed on sheets, on macOS &lt; 10.14. Please check <a href="https://github.com/luckymarmot/ThemeKit/issues/18#issuecomment-396553982">this comment</a> for a brief explanation on how to fix it, and a small project demonstrating the issue and the fix.</p>
<h3 id='strong-scrollbars-appear-all-white-on-dark-themes-strong' class='heading'><strong>Scrollbars appear all white on dark themes!</strong></h3>

<p>If the user opts for always showing the scrollbars on <em>System Preferences</em>, scrollbars may render all white on dark themes. To bypass this, we need to observe for theme changes and change its background color directly. E.g.,</p>
<pre class="highlight swift"><code>   <span class="n">scrollView</span><span class="p">?</span><span class="o">.</span><span class="n">backgroundColor</span> <span class="o">=</span> <span class="kt">ThemeColor</span><span class="o">.</span><span class="n">myBackgroundColor</span>
   <span class="n">scrollView</span><span class="p">?</span><span class="o">.</span><span class="n">wantsLayer</span> <span class="o">=</span> <span class="kc">true</span>
   <span class="kt">NotificationCenter</span><span class="o">.</span><span class="k">default</span><span class="o">.</span><span class="nf">addObserver</span><span class="p">(</span><span class="nv">forName</span><span class="p">:</span> <span class="o">.</span><span class="n">didChangeTheme</span><span class="p">,</span> <span class="nv">object</span><span class="p">:</span> <span class="kc">nil</span><span class="p">,</span> <span class="nv">queue</span><span class="p">:</span> <span class="kc">nil</span><span class="p">)</span> <span class="p">{</span> <span class="p">(</span><span class="n">note</span><span class="p">)</span> <span class="k">in</span>
     <span class="n">scrollView</span><span class="p">?</span><span class="o">.</span><span class="n">verticalScroller</span><span class="p">?</span><span class="o">.</span><span class="n">layer</span><span class="p">?</span><span class="o">.</span><span class="n">backgroundColor</span> <span class="o">=</span> <span class="kt">ThemeColor</span><span class="o">.</span><span class="n">myBackgroundColor</span><span class="o">.</span><span class="n">cgColor</span>
   <span class="p">}</span>
</code></pre>
<h3 id='strong-i-39-m-having-font-smoothing-issues-strong' class='heading'><strong>I&rsquo;m having font smoothing issues!</strong></h3>

<p>You may run into font smoothing issues when you use text without a background color set. Bottom line is, always specify/draw a background when using/drawing text. </p>

<ol>
<li><p>For controls like <code>NSTextField</code>, <code>NSTextView</code>, etc:</p>
<pre class="highlight plaintext"><code>Specify a background color on the control. E.g.,

```swift
control.backgroundColor = NSColor.black
```
</code></pre>

<ol>
<li><p>For custom text rendering:</p>

<p>First draw a background fill, then enable font smoothing and render your text. E.g.,</p>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">context</span> <span class="o">=</span> <span class="kt">NSGraphicsContext</span><span class="o">.</span><span class="nf">current</span><span class="p">()?</span><span class="o">.</span><span class="n">cgContext</span>
<span class="kt">NSColor</span><span class="o">.</span><span class="n">black</span><span class="o">.</span><span class="nf">set</span><span class="p">()</span>
<span class="n">context</span><span class="p">?</span><span class="o">.</span><span class="nf">fill</span><span class="p">(</span><span class="n">frame</span><span class="p">)</span>
<span class="n">context</span><span class="p">?</span><span class="o">.</span><span class="nf">saveGState</span><span class="p">()</span>
<span class="n">context</span><span class="p">?</span><span class="o">.</span><span class="nf">setShouldSmoothFonts</span><span class="p">(</span><span class="kc">true</span><span class="p">)</span>

<span class="c1">// draw text...</span>

<span class="n">context</span><span class="p">?</span><span class="o">.</span><span class="nf">restoreGState</span><span class="p">()</span>
</code></pre>

<p>As a last solution - if you really can&rsquo;t draw a background color - you can disable font smoothing which can slightly improve text rendering:</p>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">context</span> <span class="o">=</span> <span class="kt">NSGraphicsContext</span><span class="o">.</span><span class="nf">current</span><span class="p">()?</span><span class="o">.</span><span class="n">cgContext</span>
<span class="n">context</span><span class="p">?</span><span class="o">.</span><span class="nf">saveGState</span><span class="p">()</span>
<span class="n">context</span><span class="p">?</span><span class="o">.</span><span class="nf">setShouldSmoothFonts</span><span class="p">(</span><span class="kc">false</span><span class="p">)</span>

<span class="c1">// draw text...</span>

<span class="n">context</span><span class="p">?</span><span class="o">.</span><span class="nf">restoreGState</span><span class="p">()</span>
</code></pre></li>
<li><p>For custom <code>NSButton</code>&lsquo;s:</p>

<p>This is more tricky, as you will need to override private methods. If you are distributing your app on the Mac App Store, you must first check if this is allowed.</p>

<p>a) override the private method <code>_backgroundColorForFontSmoothing</code> to return your button background color.</p>

<p>b) if (a) isn&rsquo;t sufficient, you will also need to override <code>_textAttributes</code> and change the dictionary returned from the <code>super</code> call to provide your background color for the key <code>NSBackgroundColorAttributeName</code>.</p></li>
</ol></li>
</ol>
<h2 id='license' class='heading'>License</h2>

<p><em>ThemeKit</em> is available under the MIT license. See the <a href="LICENSE">LICENSE</a> file for more info.</p>

          </section>
        </section>
        <section id="footer">
          <p>© 2016-2017 <a class="link" href="https://paw.cloud" target="_blank" rel="external">Paw</a> &amp; <a class="link" href="http://nunogrilo.com" target="_blank" rel="external">Nuno Grilo</a> under <a class="link" href="https://github.com/luckymarmot/ThemeKit/blob/master/LICENSE" target="_blank" rel="external">MIT License</a>.</p>
          <p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.7</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
        </section>
      </article>
    </div>
  </body>
</div>
</html>
